package com.example.shop.goods.dto;

import com.example.shop.common.api.ResponseResult;
import com.example.shop.pojo.GoodsClass;
import lombok.*;
import lombok.experimental.Accessors;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import javax.validation.constraints.NotNull;
import java.io.Serializable;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class GoodsStyle implements Serializable {
    @NotNull
    @Field(type = FieldType.Keyword)
    private String classPicture;
    //该型号名
    @NotNull
    @Field(type = FieldType.Keyword)
    private String goodsClass;
    //该型号的价格
    @NotNull
    private Integer classPrice;
    //该型好的库存量
    @NotNull
    private Integer classInventory;

    public void setClassPicture(String classPicture) {
        this.classPicture = ResponseResult.toRequestPath(classPicture);
    }

    public static GoodsStyle getGoodsStyle(GoodsClass goodsClass){
        GoodsStyle goodsStyle = new GoodsStyle();
        goodsStyle.setClassPicture(goodsClass.getGoodsClassPicture());
        goodsStyle.setGoodsClass(goodsClass.getGoodsClass());
        goodsStyle.setClassPrice(goodsClass.getClassPrice());
        goodsStyle.setClassInventory(goodsClass.getClassInventory());
        return goodsStyle;
    }


    @Override
    public String toString() {
        return "GoodsStyle{" +
                "classPicture='" + classPicture + '\'' +
                ", goodsClass='" + goodsClass + '\'' +
                ", classPrice=" + classPrice +
                ", classInventory=" + classInventory +
                '}';
    }
}
